import { createRouter, createWebHistory } from 'vue-router';
import NProgress from 'nprogress'; // progress bar
import 'nprogress/nprogress.css';

import { appRoutes } from './routes';
import { NOT_FOUND_ROUTE } from './routes/base';
import createRouteGuard from './guard';

NProgress.configure({ showSpinner: false }); // NProgress Configuration

const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      redirect: 'login',
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/views/login/index.vue'),
      meta: {
        requiresAuth: false,
      },
    },
    {
      path: '/active-user',
      name: 'activeUser',
      component: () => import('@/views/active-user/index.vue'),
      meta: {
        requiresAuth: false,
      },
    },
    {
      path: '/layout',
      name: 'layout',
      component: () => import('@/layout/base-layout.vue'),
      meta: {
        requiresAuth: false,
      },
      children: [
        {
          path: '/project/:projectId',
          name: 'project',
          component: () => import('@/layout/menu-layout.vue'),
          meta: {
            requiresAuth: false,
          },
          children: [...appRoutes],
        },
        {
          path: '/dashboard',
          name: 'dashboard',
          component: () => import('@/views/dashboard/index.vue'),
          meta: {
            requiresAuth: false,
          },
        },
        {
          path: '/user-setting',
          name: 'Setting',
          component: () => import('@/views/user/index.vue'),
          meta: {
            requiresAuth: false,
          },
        },
      ],
    },
    NOT_FOUND_ROUTE,
  ],
  scrollBehavior() {
    return { top: 0 };
  },
});

createRouteGuard(router);

export default router;
